<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      >
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content"> 
            <div class="Post">
             <h:form id="naviForm">
            <h:panelGrid columns="4">
                <h:outputText value="Filter:" rendered="#{modifyGroupBean.naviSubject}"/>
                <p:commandLink ajax="true" value="#{modifyGroupBean.selectedSubject.code}" action="#{modifyGroupBean.toChooseSubject()}"  rendered="#{modifyGroupBean.naviSubject}"  update=":naviForm,:subjectForm,:groupForm,:userForm"/>
                <h:outputText value="-->" rendered="#{modifyGroupBean.naviGroup}"/>
                <p:commandLink ajax="true" value="#{modifyGroupBean.selectedGroup.code}" rendered="#{modifyGroupBean.naviGroup}"  action="#{modifyGroupBean.toChooseGroup()}"  update=":naviForm,:subjectForm,:groupForm,:userForm"/>
            </h:panelGrid>
            <h:panelGrid columns="1">
                <p:commandLink  value="Back to edit" action="#{modifyGroupBean.backToEdit()}" rendered="#{modifyGroupBean.back}" ajax="true" update=":naviForm,:subjectForm,:groupForm,:userForm"/>
            </h:panelGrid>  
        </h:form>
            </div>
             <div class="Post">
        <h:form id="subjectForm">
            <p:dataTable value="#{modifyGroupBean.allSubjects}" var="subject" selectionMode="single"
                         selection="#{modifyGroupBean.selectedSubject}"
                         rowKey="#{subject.id}" paginator="true" paginatorAlwaysVisible="false" rows="30"
                         emptyMessage="There are no subjects in system."  rendered="#{modifyGroupBean.displaySubjects}">
                <f:facet name="header" >
                    <h:outputText value="Choose subject" />
                </f:facet>
                <p:column headerText="Code">
                    <h:outputText value="#{subject.code}" />
                </p:column>
                <p:column headerText="Description">
                    <h:outputText value="#{subject.description}" />       
                </p:column>
            </p:dataTable>
            <p:commandButton value="Choose" action="#{modifyGroupBean.chooseSubject()}"  rendered="#{modifyGroupBean.displaySubjects}" ajax="true" update=":groupForm,:subjectForm,:naviForm"/>  
        </h:form>
             </div>
             <div class="Post">
        <h:form id="groupForm">
            <p:dataTable value="#{modifyGroupBean.groups}" var="group" selectionMode="single"
                         selection="#{modifyGroupBean.selectedGroup}"
                         rowKey="#{group.id}" paginator="true" paginatorAlwaysVisible="false" rows="30"
                         emptyMessage="There are no group on subject #{modifyGroupBean.selectedSubject.code} in system."
                         id="groupTable" rendered="#{modifyGroupBean.displayGroups}">
                <f:facet name="header" >
                    <h:outputText value="Choose group" />
                </f:facet>
                <p:column headerText="Code">
                    <h:outputText value="#{group.code}" />
                </p:column>
                <p:column headerText="Day">
                    <h:outputText value="#{group.dayOfTeach}" />       
                </p:column>
                <p:column headerText="Start time">
                    <h:outputText value="#{group.startTime}" >
                        <f:convertDateTime type="time" timeZone="Europe/Prague"></f:convertDateTime>
                    </h:outputText>
                </p:column>
                <p:column headerText="Stop time">
                    <h:outputText value="#{group.stopTime}" >
                        <f:convertDateTime type="time" timeZone="Europe/Prague"></f:convertDateTime>
                    </h:outputText>
                </p:column>
                <p:column headerText="Kantor">
                    <h:outputText value="#{group.kantor.name} #{group.kantor.surname}" />       
                </p:column>
                <p:column headerText="Kantor login">
                    <h:outputText value="#{group.kantor.login}" />       
                </p:column>
            </p:dataTable>
            <p:commandButton value="Choose" action="#{modifyGroupBean.chooseGroup()}" rendered="#{modifyGroupBean.displayGroups}" update=":userForm,:groupForm,:naviForm"/>  
            <p:commandButton value="Remove selected group"  rendered="#{modifyGroupBean.displayGroups}" update=":userForm,:groupForm,:naviForm" oncomplete="confirmDialog.show()"/>  
        </h:form>
             </div>
           
        <h:form id="userForm">
              <div class="Post">
            <h:panelGrid columns="2" styleClass="gridCenter" rendered="#{modifyGroupBean.displayDetails}" >
                <h:outputText value="Group code: " />
                <p:inputText  value="#{modifyGroupBean.upadtedGroup.code}"></p:inputText> 
                <h:outputText value="Start time: " />
                <p:calendar value="#{modifyGroupBean.upadtedGroup.startTime}" pattern="HH:mm" timeOnly="true" >                   
                </p:calendar>
                <h:outputText value="Stop time: " />
                <p:calendar value="#{modifyGroupBean.upadtedGroup.stopTime}" pattern="HH:mm" timeOnly="true" >
                </p:calendar>
                <h:outputText value="Day of teach " />
                <p:inputText  value="#{modifyGroupBean.upadtedGroup.dayOfTeach}"></p:inputText> 
            </h:panelGrid>
              </div>
              <div class="Post">
            <h:panelGrid columns="2" id="kantorGrid"  rendered="#{modifyGroupBean.displayDetails}">
               
                <h:outputText value="Login" />
                <h:outputText  value="#{modifyGroupBean.upadtedGroup.kantor.login}"/>
                <h:outputText value="Name: " />
                <h:outputText value="#{modifyGroupBean.upadtedGroup.kantor.name}" />   
                <h:outputText value="Surname" />
                <h:outputText value="#{modifyGroupBean.upadtedGroup.kantor.surname}" />   
                <h:outputText value="Email" />
                <h:outputText  value="#{modifyGroupBean.upadtedGroup.kantor.email}"/>
        
            </h:panelGrid>
              </div>

            <div class="Post">
            <p:dataTable value="#{modifyGroupBean.studentsInGroup}" var="student"
                         rowKey="#{student.id}" paginator="true" paginatorAlwaysVisible="false" rows="30"
                         emptyMessage="There are no students in group #{modifyGroupBean.selectedGroup.code} in system."
                         id="studentTable" rendered="#{modifyGroupBean.displayDetails}">

                <f:facet name="header" >
                    <p:commandButton value="Add students" action="#{modifyGroupBean.loadStudents()}" oncomplete="addUserToGroupDialog.show()" /> <br/>
                    <h:outputText value="Students in group" />
                </f:facet>
                <p:column headerText="Login">
                    <h:outputText value="#{student.login}" />
                </p:column>
                <p:column headerText="Name">
                    <h:outputText value="#{student.name}" />       
                </p:column>
                <p:column headerText="Surname">
                    <h:outputText value="#{student.surname}" />       
                </p:column>
                <p:column headerText="E-mail">
                    <h:outputText value="#{student.email}" />       
                </p:column>    
                <p:column headerText="Remove student">
                    <p:commandButton  value="remove" action="#{modifyGroupBean.removeStudents(student)}" update=":userForm,studentTable" ajax="true" />       
                </p:column>  
            </p:dataTable>
            </div>
                <div class="Post">
            <p:commandButton value="Save" update=":userForm,:groupForm" rendered="#{modifyGroupBean.displayDetails}"
                             action="#{modifyGroupBean.modify()}"/>  
                </div>
        </h:form>
            
            <p:dialog header="Users to add to group :#{modifyGroupBean.upadtedGroup.code} in subject #{modifyGroupBean.upadtedGroup.subject.code}" 
                      widgetVar="addUserToGroupDialog" resizable="false" 
                      width="900" height="600"  modal="true" appendToBody="true"
                      dynamic="true"  >  
                <h:form id="studentsToallTable">
                <p:dataTable 
                    rowKey="#{studentToAdd.id}"
                    var="studentToAdd" value="#{modifyGroupBean.studentToAdd}"  
                    paginator="true" paginatorAlwaysVisible="false" rows="30"
                    id="studentsAddTable" selectionMode="multiple" selection="#{modifyGroupBean.selectedStudents}"
                    emptyMessage="No students were found by specifi criteria.">  
                    <f:facet name="header">  
                        <h:outputText value="Student to add" />  <br/>
                    </f:facet>  
                    <p:column headerText="Login">  
                        <h:outputText value="#{studentToAdd.login}" />  
                    </p:column> 
                    <p:column headerText="Name">  
                        <h:outputText value="#{studentToAdd.name}" />  
                    </p:column>  
                    <p:column headerText="Surname">  
                        <h:outputText value="#{studentToAdd.surname}" />  
                    </p:column> 
                    <p:column headerText="Email">  
                        <h:outputText value="#{studentToAdd.email}" />  
                    </p:column> 
                </p:dataTable> 
                <p:commandButton value="Add" update=":userForm" action="#{modifyGroupBean.addStudentToGroup()}" 
                                 ajax="true" ></p:commandButton>
                <p:commandButton value="Close" 
                                 ajax="true" oncomplete="addUserToGroupDialog.hide();"></p:commandButton>
                </h:form>
            </p:dialog>  
             <p:dialog header="Kantor to group :#{modifyGroupBean.upadtedGroup.code} in subject #{modifyGroupBean.upadtedGroup.subject.code}" 
                      widgetVar="changeKantorDialog" resizable="false" 
                      width="900" height="600"  modal="true"
                      dynamic="true"  >  
                 <h:form id="kantorToChangeTable">
                <p:dataTable 
                    rowKey="#{kantorToChange.id}"
                    var="kantorToChange" value="#{modifyGroupBean.kantorsToAdd}"  
                    paginator="true" paginatorAlwaysVisible="false" rows="30"
                    id="kantorAddTable" selectionMode="single" selection="#{modifyGroupBean.selectedKantor}"
                    emptyMessage="No students were found by specifi criteria.">  
                    <f:facet name="header">  
                        <h:outputText value="Kantor to change" />  <br/>
                    </f:facet>  
                    <p:column headerText="Login">  
                        <h:outputText value="#{kantorToChange.login}" />  
                    </p:column> 
                    <p:column headerText="Name">  
                        <h:outputText value="#{kantorToChange.name}" />  
                    </p:column>  
                    <p:column headerText="Surname">  
                        <h:outputText value="#{kantorToChange.surname}" />  
                    </p:column> 
                    <p:column headerText="Email">  
                        <h:outputText value="#{kantorToChange.email}" />  
                    </p:column> 
                </p:dataTable> 
                 <p:commandButton value="Change" update=":userForm" action="#{modifyGroupBean.changeKantor()}" 
                                 ajax="true" ></p:commandButton>
                <p:commandButton value="Close" 
                                 ajax="true" oncomplete="changeKantorDialog.hide();"></p:commandButton>
                 </h:form>
            </p:dialog>
            <p:dialog header="Confirm to remove :#{modifyGroupBean.selectedGroup.code} in subject #{modifyGroupBean.selectedGroup.subject.code}" 
                      widgetVar="confirmDialog" resizable="false" 
                      width="300" height="200"  modal="true"  appendToBody="true"
                      dynamic="true"  >  
                <h:form id="confirDialog">
                <h:outputText value="Are you sure to delete group #{modifyGroupBean.selectedGroup.code} in subject #{modifyGroupBean.selectedGroup.subject.code} 
                              The system will delete all assignment and teams in this group. "/>
                <h:panelGrid columns="2" styleClass="gridCenter">
                <p:commandButton value="Yes" update=":userForm,:groupForm" action="#{modifyGroupBean.removeGroup()}" 
                                 ajax="true" oncomplete="confirmDialog.hide();"></p:commandButton>
                <p:commandButton value="Close" 
                                 ajax="true" oncomplete="confirmDialog.hide();"></p:commandButton>
                </h:panelGrid>
                </h:form>
            </p:dialog>  
</ui:define>
    </ui:composition>
</html>